<template>
	<!-- accountdis账户与折扣设置 -->
	<view class="wp">
		<uni-forms ref="form" label-width="150px" label-position="top" :modelValue="dataInfo">
			<uni-forms-item label="商家让利设置" required name="discount">
				<uni-easyinput v-model="dataInfo.discount" placeholder="请输入折扣" />
				<uni-card :border="false" spacing="5px 0" padding="0" :is-shadow="false" is-full>
					<text class="message">填写1-98数值</text>
				</uni-card>
				<uni-card :border="false" spacing="5px 0" padding="0" :is-shadow="false" is-full>
					<text class="message">如输入98，用户付钱后，您得到98%的现金</text>
				</uni-card>
			</uni-forms-item>
			<uni-forms-item label="支付宝收款姓名" required name="aliname">
				<uni-easyinput v-model="dataInfo.aliname" placeholder="请输入姓名" />
			</uni-forms-item>
			<uni-forms-item label="支付宝收款账户(手机号)" required name="aliaccount">
				<uni-easyinput type="number" v-model="dataInfo.aliaccount" placeholder="请输入支付宝账户" />
			</uni-forms-item>


		</uni-forms>
		<view class="" style="text-align: center;">
			<button class="sub" :disabled="isstop" @click="submit">提交</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				uid: '',
				dataInfo: {
					aliaccount: "",
					aliname: "",
					discount: ""
				},
				isstop: false,
				rules: {
					aliname: {
						rules: [{
							required: true,
							errorMessage: '姓名不能为空'
						}]
					},
					aliaccount: {
						rules: [{
							required: true,
							errorMessage: '支付宝账号不能为空'
						}]
					},
					discount: {
						rules: [{
							required: true,
							errorMessage: '请正确填写折扣'
						}, {
							validateFunction: function(rule, value, data, callback) {
								let reg = /^\d+\.?\d?$/;
								if (!reg.test(value) || value > 100) callback('请正确填写折扣');
							}
						}]
					},
				},
			}
		},
		onReady() {
			this.$refs.form.setRules(this.rules)
		},
		onLoad(options) {
			this.uid = options.uid;
			this.getInfo();
		},
		methods: {
			getInfo() {
				this.$axios('info/getPaydiscount', 'POST', 'supplier', {
					uid: this.uid
				}).then(res => {
					if (res.data.code == 200) {
						this.dataInfo = res.data.data;
					}
				})
			},
			submit() {
				this.$refs.form.validate().then(res => {
					this.isstop = true;
					this.$axios('info/savePaydiscount', 'POST', 'supplier', {
						...this.dataInfo,
						uid: this.uid
					}).then(res => {
						this.isstop = false;
						if (res.data.code == 200) {
							this.$api.msg('设置成功！');
						}
					})
				}).catch(err => {
					console.log('err', err);
				})
			}
		}
	}
</script>

<style lang="scss">
	.wp {
		padding: 20upx;
	}

	.message {
		color: #4399fc;
		font-size: 24upx;
	}

	.sub {
		background: #18bc37;
		color: #fff;
		font-size: 28upx;
		line-height: 80upx;
		width: 90%;
	}
</style>